#include "SButtonShowAll.h"

#include <core/StyleMgr.h>

#include <QMouseEvent>

SButtonShowAll::SButtonShowAll(QWidget* parent /*= nullptr*/)
    : QPushButton(parent) {
  QString style = QString(
                      "QPushButton:checked {background-color: #%1;color: "
                      "#%2;border: 1px solid #%2;;border-radius:2px;}"
                      "QPushButton {background-color:#%3;}")
                      .arg(NAME_COLOR("BackNormal").rgb(), 0, 16)
                      .arg(NAME_COLOR("Highlight").rgb(), 0, 16)
                      .arg(NAME_COLOR("TabBackNormal").rgb(), 0, 16);

  setStyleSheet(style);
  setCheckable(true);
}

void SButtonShowAll::mouseReleaseEvent(QMouseEvent* event) {
  if (event->button() == Qt::LeftButton &&
      rect().contains(event->localPos().toPoint())) {
    if (!isChecked()) {
      setChecked(true);
      emit clicked();
    }
  }
}